package com.github.jexl;

import com.googlecode.aviator.AviatorEvaluator;
import org.junit.jupiter.api.Test;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangcheng
 * @date 2023/3/28 11:00
 * @description
 */
public class AviatorTest {

    @Test
    public void test() {
        Map<String, Object> env = new HashMap<>();
        env.put("count", 11);
        String expression = "count > 10";
        Object execute = AviatorEvaluator.execute(expression, env);
        System.out.println(execute);
    }

    @Test
    public void testJs() throws ScriptException {
// 1、获得脚本引擎对象,选择脚本语言
        ScriptEngineManager manager = new ScriptEngineManager();
// 亦可以是js缩写，代表JavaScript脚本语言
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        Object result = engine.eval(" var num  = 5+2;");
    }
}
